<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2020-07-03
 * Time: 11:25
 */

namespace app\api\controller\v1;


use app\api\model\LinUser;
use think\facade\Request;

class LinUserAdmin
{
    /**
     * 获取总管理员信息列表
     */
    public function getDataList($page,$limit)
    {
        $query = LinUser::where('id','gt',1)
            ->where('admin',2)
            ->order('id desc');
        $count = $query->count();
        $result = $query->page($page, $limit)->select()->toArray();
        $data['count'] = $count;
        $data['data'] = $result;
        return $data;
    }

    /**
     * 获取详情
     * @validate('IdMustBePositiveInt')
     */
    public function getDataInfo($id)
    {
        return LinUser::where('id',$id)->find();
    }

    /**
     * 创建分类
     */
    public function createData()
    {
        $data = Request::post();
        $data['password'] = md5($data['password']);
        $data['admin'] = 2;
        $data['create_time'] = date('Y-m-d H:i:s',time());
        $data['update_time'] = date('Y-m-d H:i:s',time());
        LinUser::create($data);
        return writeJson(201, [], '添加成功！');
    }

    /**
     * 更新信息
     */
    public function updateData()
    {
        $data = Request::put();
        $data['password'] = md5($data['password']);
        $data['update_time'] = date('Y-m-d H:i:s',time());
        $mode = new LinUser();
        $mode->allowField(true)->save($data,['id',$data['id']]);
        return writeJson(202, [], '修改成功！');
    }

    /**
     * 删除信息
     * @validate('IdMustBePositiveInt')
     */
    public function deleteData($id)
    {
        LinUser::where('id',$id)->update([
            'delete_time' => date('Y-m-d H:i:s',time())
        ]);
        return writeJson(203, [], '删除成功！');
    }
}